import { request } from '@umijs/max';

export function GetUserFnc(data: {
  query: string;
  pagenum: number;
  pagesize: number;
}) {
  return request(
    `/users?query=${data.query}&pagenum=${data.pagenum}&pagesize=${data.pagesize}`,
    {
      method: 'get',
    },
  );
}

// 更改switch 状态
export function ChangeSwitchFnc(data: { id: number; state: boolean }) {
  return request(`/users/${data.id}/state/${data.state}`, {
    method: 'put',
  });
}

// 删除用户
export function RemoveUserFnc(id: number) {
  return request(`/users/${id}`, {
    method: 'delete',
  });
}

// 添加用户
export function AddUserFnc(data: {
  username: string;
  password: string;
  email: string;
  mobile: string;
}) {
  // 添加用户
  return request('/users', {
    method: 'post',
    data: data,
  });
}

// 打开修改盒子 获取对应的user信息
export function GetUserInfoFnc(id: number) {
  return request(`/users/${id}`, {
    method: 'get',
  });
}

// 修改用户
export function EditUserFnc(id: number, data: any) {
  return request(`/users/${id}`, {
    method: 'put',
    data: data,
  });
}

// 打开分配角色盒子 获取对应的角色信息
export function GetRolesFnc() {
  return request('/roles', {
    method: 'get',
  });
}

// 保存角色分配
export function SaveRolesFnc(id: number, data: any) {
  return request(`/users/${id}/role`, {
    method: 'put',
    data: data,
  });
}
